<?php


namespace app\admin\controller;


use app\admin\service\RequestService;
use app\model\AdType;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;


class AdCateController extends AController{

    public function index(RequestService $curdService){
        $list = $curdService->index(new AdType(), [], [], false);
        return jsonSuccess([
            'items' => $list
        ]);
    }

    public function add(RequestService $curdService){
        return $curdService->add(new AdType());
    }

    public function edit(RequestService $curdService){
        if (request()->isPost()){
            return $curdService->edit(new AdType());
        }else{
            $id = request()->param('id');
            $info = AdType::find($id);
            return jsonSuccess([
                'info' => $info
            ]);
        }
    }

    /**
     * @throws ModelNotFoundException
     * @throws DataNotFoundException
     * @throws DbException
     */
    public function options(): \think\response\Json
    {

        $options = AdType::where('status',1)->select();

        return jsonSuccess([
            'options' => $options
        ]);
    }

}
